<template>
  <div id="home">
    <el-header>
      <p class="header_p1"><span class="iconfont icon-shousuo"></span> 宿舍管理系统</p>
      <div class="header_div1">
        <img src="../assets/images/111.jpg" alt="">
        <el-dropdown trigger="click">
          <span class="el-dropdown-link">
            {{$store.state.userInfo.userName}}<i class="el-icon-caret-bottom el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item class="clearfix">
              你干嘛
              <el-badge class="mark" />
            </el-dropdown-item>
            <el-dropdown-item class="clearfix" @click.native="exitLogin">
              退出
              <el-badge class="mark" />
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside width="250px">
        <el-menu :default-active="$route.path" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" router>
          <el-menu-item index="/home/welcome">
            <template slot="title">
              <i class="iconfont icon-gonggao"></i>
              <span slot="title">公告主页</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/home/dormitory" v-if="admin">
            <template slot="title">
              <i class="iconfont icon-sushe"></i>
              <span>宿舍管理</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/home/student" v-if="!student">
            <template slot="title">
              <i class="iconfont icon-xuesheng"></i>
              <span>学生管理</span>
            </template>
          </el-menu-item>
          <!-- 没有办法的办法 -->
          <el-menu-item index="/home/studentOwn" v-if="student">
            <template slot="title">
              <i class="iconfont icon-xuesheng"></i>
              <span>学生管理</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/home/announcement" v-if="admin">
            <template slot="title">
              <i class="iconfont icon-gonggao1"></i>
              <span>公告管理</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/home/admin" v-if="superAdmin">
            <template slot="title">
              <i class="iconfont icon-guanliyuan"></i>
              <span>管理员管理</span>
            </template>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
    <!-- 提示 -->
    <el-dialog title="警告" :visible.sync="noMoneyVisible" align="center">
      <span>宿舍没钱了,快去充钱</span>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button @click="noMoneyVisible = false">取 消</el-button>
        <el-button type="primary" @click="noMoneyVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data () {
    return {
      superAdmin: false,
      admin: false,
      student: false,

      // 提示
      noMoneyVisible: false
    };
  },
  methods: {
    exitLogin () {
      this.$store.state.token = ''
      this.$store.state.userInfo = ''
      this.$store.state.tagNames = []
      this.$router.push('/login')
    },
    // 权限渲染页面(虚假的)
    getPermissions () {
      let type = this.$store.state.userInfo.userType
      if (type === 0) {
        this.superAdmin = true
        this.admin = true
      } else if (type === 1) {
        this.admin = true
      } else {
        this.student = true
        this.getStudent()
      }
    },
    //学生页面谈催款框
    async getStudent () {
      const result = await this.$http.post('/getStudentOwn', { s_id: this.$store.state.userInfo.userId })
      if (result.status !== 200) return this.$message.error(result.message)
      if (result.data[0].d_status === 2) {
        setTimeout(() => {
          this.noMoneyVisible = true
        }, 1000)
      }
    },
  },
  created () {
    this.getPermissions()
  },
};
</script>

<style scoped lang="less">
@bgcolor: rgb(84, 92, 100);
@fontcolor: rgb(255, 255, 255);
#home {
  width: 100%;
  height: 100%;
}
.el-aside {
  background-color: @bgcolor;
  .el-menu {
    border: none;
    .iconfont {
      margin-right: 15px;
    }
  }
}
.el-header {
  width: 100%;
  height: 60px;
  background-color: @bgcolor;
  position: relative;
  .header_p1 {
    float: left;
    margin: auto;
    width: 200px;
    height: 60px;
    line-height: 60px;
    text-align: left;
    color: @fontcolor;
    font-size: 20px;
    span {
      margin-right: 20px;
      &:hover {
        cursor: pointer;
      }
    }
  }
  .header_div1 {
    width: 150px;
    height: 40px;
    position: absolute;
    top: 0;
    bottom: 0;
    right: 20px;
    margin: auto;
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      vertical-align: middle;
      margin-right: 10px;
    }
    span {
      color: @fontcolor;
      position: relative;
      &:hover {
        cursor: pointer;
      }
    }
  }
}
.el-container {
  width: 100%;
  height: calc(100% - 60px);
}
</style>
